var ctx = ctx;
var patientId = "";
var visitId = "";
var tempInfoId = "";
$(function () {
    patientId = $("#patientIdVal").val();
    visitId = $("#visitId").val();
    tempInfoId = $("#tempInfoId").val();
    loadDiv('detailsDiv', ctx + '/nurse/nurseTempDetailInfo/index?tempInfoId='+tempInfoId);
    loadDiv('eventDiv', ctx + '/nurse/nurseVitalSignsRec/index?patientId=' + patientId + '&visitId=' + visitId+'&tempInfoId='+tempInfoId);
});

/*保存主要护理项目及辅助护理项目*/
function saveTempInfo(formId,saveUrl,loadUrl) {
    if(flag){
        flag=false;
        var formJson = fromJson(formId);
        formJson = formJson.substring(0, formJson.length - 1);
        var tableJson =   JSON.stringify( $("#contentTable").serialize());
        var submitJson = formJson + ",\"nurseTempDetailInfos\":" + tableJson + "}";
        $.ajax({
            type: "POST",
            data:submitJson,
            url: saveUrl,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    toastr.success("保存成功");
                   /* loadDiv('applyDiv', ctx + '/doctor/prescriptionApply/applyIndex?clinicId=' + clinicId + '&patientId=' + patientId + '&visitId=' + visitId);
                    loadDiv('prescChineseItemDiv', ctx + '/doctor/prescriptionItem/chineseIndex?applyId=' + applyId);*/
                } else {
                    flag=true;
                    toastr.error(data.data);
                }
            },
            error: function (data) {
                flag=true;
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }
    return false;
}



/*项目事件*/
function addEventItem() {
    tempInfoId = $("#tempInfoId").val();
     $("#eventDiv").attr("class", " panel col-lg-8");
     $("#eventFormDiv").show('normal');
     loadDiv('eventFormDiv', ctx + '/nurse/nurseVitalSignsRec/form?patientId=' + patientId+'&visitId='+visitId);



}
/*保存项目事件*/
function saveEvent(divId,formId,saveUrl,loadUrl) {
    if(flag){
        if ($('#' + formId).parsley().validate()) {
            flag=false;
            $.ajax({
                type: "POST",
                data: $("#"+formId).serialize(),
                url: saveUrl,
                dataType: "json",
                success: function (data) {
                    if (data.code == "success") {
                        toastr.success("保存成功");
                        closeDiv();
                         loadDiv(divId, loadUrl+'?patientId=' + patientId + '&visitId=' + visitId+'&tempInfo.id='+$('#tempInfoId').val());
                    } else {
                        toastr.error(data.data);
                    }
                },
                error: function (data) {
                    toastr.error('网络连接错误,请检查网络');
                }
            });
        }

    }
    return false;

}

function closeDiv(){
    $("#eventDiv").attr("class", " panel col-lg-12");
    $("#eventDiv").show('normal');
    $("#eventFormDiv").hide();
}

/**
* 生成三测单
*/
function generateInfo(){

    $.ajax({
        type: "POST",
        data: '{"visitId":"'+visitId+'","patientId":"'+patientId+'"}',
        url: ctx+"/nurse/nurseTempInfo/generateInfo",
        dataType: "json",
        success: function (data) {
            sub = true;
            if(data.code=='1'){
                printWindow(data.data);
            } else {
                toastr.error(data.data);
            }
        },
        error: function (data) {
            toastr.error('网络连接错误,请检查网络');
        }
    });
   /*
    $.postJSON(ctx+"/nurse/nurseTempInfo/generateInfo",'{"visitId":"'+visitId+'","patientId":"'+patientId+'"}',function(data){
        sub = true;
        if(data.code=='1'){
            printWindow(data.data);
        }

    }),function(data){
        $.messager.alert("提示信息", "生成失败，请联系管理员", "error");
    }*/
}
